#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(){
    int num = 10;
    printf("Before fork, num = %d\n", num);

    pid_t pid = fork();
    if (pid == -1)
    {
        perror("fork failed\n");
        return 1;
    }else if (pid == 0){
        // child process
        num++;
        printf("Child process(%d), num = %d\n", getpid(), num);
    } else{
        // parent process
        num--;
        printf("Parent process(%d), num = %d\n", getpid(), num);
    }

    printf("After fork, num = %d\n", num);
    
}